home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0696A.ZIP
/
TIMEDAT2.C
< prev
next >
Wrap
Text File
|
1987-05-25
|
2KB
|
96 lines
/**
* timedat2
*
* check env if not found TZ variable add it....
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <spstd.h>
#include <time.h>
main(argc, argv, envp)
int argc;
char **argv;
char **envp;
{
register char *ep;
static char timestr[] = { "TZ" };
static char pgm[MAXNAME + 1] = { "showenv" };
extern void getpname(char *, char *);
extern void settz();
extern void telltime();
/* use an alias if one given to this program */
if (_osmajor >= 3)
getpname(*argv, pgm);
/* if no arguments show the full environment list */
/*
* treat all args as DOS variable names and display values of
* only specified variables
*/
if ((ep = getenv(strupr(timestr))) == NULL)
{
fprintf(stderr, "%s not defined\n", timestr);
fprintf(stderr, "Adding set TZ=EST5EDT\n");
settz();
}
else
printf("%s=%s\n", timestr, ep);
telltime();
exit(0);
}
void settz()
{
register char **p;
static char tzstring[] = { "TZ" };
static char pgm[MAXNAME + 1]= { "setmydir" };
extern void getpname(char *, char *);
extern void err_exit(char *, char *,int);
/* try to add TZ variable to environment */
if (putenv("TZ=EST5EDT") == -1)
err_exit(pgm, "ERROR CHANGING ENVIRONMENT", 1);
/* display the environment for this process */
for (p = environ; *p; p++) {
printf("%s\n", *p);
}
return(0);
}
void err_exit(pname, str, errlvl)
char *pname;
char *str;
int errlvl;
{
fputs(pname, stderr);
fputc(':',stderr);
fputc(' ',stderr);
/* for fatal add perror(str); */
exit(errlvl);
}
void telltime()
{
long now;
struct tm *tbuf;
/* get TZ data into global variables */
tzset();
/* display the global time values */
printf("daylight savings time flag = %d\n", daylight);
printf("difference (in seconds) from GMT = %ld\n", timezone);
printf("standard time zone string is %s\n", tzname[0]);
printf("daylight time zone string is %s\n", tzname[1]);
/**
* display the current date and time values for local and universal time
**/
now = time(NULL);
printf("\nctime():\t%s\n", ctime(&now));
tbuf = localtime(&now);
printf("local time:\t%s\n", asctime(tbuf));
tbuf = gmtime(&now);
printf("universal time:\t%s\n", asctime(tbuf));
return(0);
}